﻿using Glorysoft.Auto.Xfw;
using Glorysoft.EAP.Core;
using Glorysoft.EAP.Core.Entities;
using Glorysoft.EAP.Core.Enums;
using Glorysoft.EAP.EAPClient.Common;
using Glorysoft.EAP.EAPClient.Model;
using Glorysoft.EAP.EAPClient.ViewModel;
using Microsoft.Extensions.Configuration;
using Serilog.Core;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;

namespace Glorysoft.EAP.EAPClient
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    /// <summary>
    /// MainWindow2.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public static string eapstate = string.Empty;
        public static Dictionary<string, List<string>> magazineDic = new Dictionary<string, List<string>>();
        public static Dictionary<string, List<string>> trayDic = new Dictionary<string, List<string>>();
        public static Dictionary<string, List<string>> traytransferDic = new Dictionary<string, List<string>>();
        public static Model.RunService ClientService = Model.RunService.Current;
        private readonly Logger ServiceLogger = XfwContext.EapLogger;
        protected readonly IConfiguration Config;
        private C_LotInfo c_LotInfo=null;
        // string catchInfor;
        // BardCodeHooK barcodeCatcher;
        // private delegate void ShowInfoDelegate(BardCodeHooK.BarCodes barCode);
        public Model.RunService ClientInfo
        {
            get
            {
                return Model.RunService.Current;
            }
        }

        /// <summary>
        /// 扫描驱动加载
        /// </summary>
        public MainWindow()
        {
            try
            {
                InitializeComponent();
                this.DataContext = new MainViewModel();
                MainViewModel.Current.InitData();
                Config = XfwContext.Configuration as IConfiguration;

                this.btnListen.Background = Brushes.Green;
                //this.btnTrackOut.Background = Brushes.Brown;
                if (ClientInfo.ClientLanguage == "CN")
                {
                    ClientInfo.LisenBtnContext = "登录";
                }
                else
                {
                    ClientInfo.LisenBtnContext = "Login";

                }
                c_LotInfo = new C_LotInfo();
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
        }

        Hook k_hook = new Hook();
        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            try
            {
                Rect rc = SystemParameters.WorkArea;//获取工作区大小 
                this.Left = (rc.Width) * 3 / 5;//设置位置 
                this.Top = 0;
                this.Width = (rc.Width) * 2 / 5; ;//
                this.Height = (rc.Height);
                TestMode.SelectedIndex = 0;//默认显示第一个选片模式
                // barcodeCatcher.Start();             



                k_hook.KeyDownEvent += K_hook_KeyDownEvent;
                k_hook.KeyHookStart(IntPtr.Zero, 0);
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
            //MyWinHost.Margin = new Thickness(ClientInfo.KvmInfo.KVMLeft, ClientInfo.KvmInfo.KVMTop, 0, 0);
            //ClientInfo.KvmInfo.KvmPanelHandle = PnlKVM.Handle;
            //MainViewModel.Current.ConnectKVM();
        }


        private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyData == System.Windows.Forms.Keys.O &&
              ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Alt) == System.Windows.Forms.Keys.Alt ||
               (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.LMenu) == System.Windows.Forms.Keys.LMenu ||
               (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.RMenu) == System.Windows.Forms.Keys.RMenu
               ) &&
               ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == System.Windows.Forms.Keys.Control) ||
               (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.LControlKey) == System.Windows.Forms.Keys.LControlKey ||
               (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.RControlKey) == System.Windows.Forms.Keys.RControlKey
               )
            {
                //keyctrl = keyalt = keyO = false;
                //MainViewModel.Current.ShowMsg(MessageType.Error, "进入o!", MessageOrigin.EAP);
                var testername = ClientInfo.EQPInfo.TesterName;
                var probername = ClientInfo.EQPInfo.ProberName;
                var USEID = ClientInfo.EQPInfo.LotList[0].UserId;
                EAPClient eapclient = new EAPClient();
                if (ClientInfo.EQPInfo.BGround == "Red")
                {
                    MainViewModel.Current.ShowMsg(MessageType.Error, "EAP Server is not connected!", MessageOrigin.EAP);

                    return;
                }
                else if (ClientInfo.EQPInfo.AuotoProcess == true)
                {
                    MainViewModel.Current.ShowMsg(MessageType.Error, "EAP Mode is online,please check!", MessageOrigin.EAP);
                    return;
                }
                // if (CMessageBox.Show(Consts.GetTranslation("Msg_online") + "：" + "EAP OnLine" + "?", Consts.GetTranslation("Msg_ConfirmInfo"), CMessageBoxButton.OKCancel) == CMessageBoxResult.OK)
                // {
                //调用server true online
                var _return = eapclient.StartProgram(testername, probername);
                if (_return != null && _return.ReturnCode == "0")
                {
                    ClientInfo.EQPInfo.AuotoProcess = true;
                    if (USEID == null)
                    {
                        ClientInfo.EQPInfo.BtnOk = Visibility.Collapsed;
                        ClientInfo.EQPInfo.Btnclean = Visibility.Collapsed;
                    }
                    else
                    {
                        ClientInfo.EQPInfo.BtnOk = Visibility.Visible;
                        ClientInfo.EQPInfo.Btnclean = Visibility.Visible;
                    }
                    // ClientInfo.EQPInfo.BtnOk = Visibility.Visible;
                    var messages = TranslateMsg.GetTranslation(CItems.AutomaticOperation);
                    MainViewModel.Current.ShowMsg(MessageType.Info, messages[RunService.Current.ClientLanguage], MessageOrigin.EAP);
                }
            }

            //ONLINE
            //if (e.KeyData == System.Windows.Forms.Keys.O &&
            //    (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Alt) == System.Windows.Forms.Keys.Alt &&
            //    (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == System.Windows.Forms.Keys.Control)
            if (e.KeyData == System.Windows.Forms.Keys.F &&
              ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Alt) == System.Windows.Forms.Keys.Alt ||
               (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.LMenu) == System.Windows.Forms.Keys.LMenu ||
               (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.RMenu) == System.Windows.Forms.Keys.RMenu
               ) &&
               ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == System.Windows.Forms.Keys.Control) ||
               (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.LControlKey) == System.Windows.Forms.Keys.LControlKey ||
               (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.RControlKey) == System.Windows.Forms.Keys.RControlKey
               )
            {
                // keyctrl = keyalt = keyC = false;
                // MainViewModel.Current.ShowMsg(MessageType.Error, "进入F!", MessageOrigin.EAP);
                var testername = ClientInfo.EQPInfo.TesterName;
                var probername = ClientInfo.EQPInfo.ProberName;
                var USEID = ClientInfo.EQPInfo.LotList[0].UserId;
                EAPClient eapclient = new EAPClient();
                if (ClientInfo.EQPInfo.AuotoProcess == false)
                {
                    MainViewModel.Current.ShowMsg(MessageType.Error, "EAP Mode is offline,please check!", MessageOrigin.EAP);
                    return;
                }
                //   if (CMessageBox.Show(Consts.GetTranslation("Msg_online") + "：" + "EAP OffLine" + "?", Consts.GetTranslation("Msg_ConfirmInfo"), CMessageBoxButton.OKCancel) == CMessageBoxResult.OK)
                //  {
                //调用server false offline
                var _return = eapclient.SendStopProcess(testername, probername);
                if (_return != null && _return.ReturnCode == "0")
                {
                    ClientInfo.EQPInfo.AuotoProcess = false;
                    //ClientInfo.EQPInfo.LotList = new System.Collections.ObjectModel.ObservableCollection<C_LotInfo>();
                    //ClientInfo.EQPInfo.LotList.Add(new C_LotInfo() { UserId = USEID });
                    c_LotInfo.Clear();
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    MainViewModel.Current.ShowMsg(MessageType.Info, messages[RunService.Current.ClientLanguage], MessageOrigin.EAP);
                }
            }

            //OFFLINE
            //if (e.KeyData == System.Windows.Forms.Keys.O &&
            //  ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Alt) == System.Windows.Forms.Keys.Alt ||
            //   (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.LMenu) == System.Windows.Forms.Keys.LMenu ||
            //   (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.RMenu) == System.Windows.Forms.Keys.RMenu
            //   ) &&
            //   ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == System.Windows.Forms.Keys.Control) ||
            //   (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.LControlKey) == System.Windows.Forms.Keys.LControlKey ||
            //   (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.RControlKey) == System.Windows.Forms.Keys.RControlKey
            //   )
            //{
            //    MessageBox.Show("999999999");
            //}
        }


        /// <summary>
        /// 最小化窗体事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        /// <summary>
        /// Ctrl+O
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommandBinding_Executed_Online(object sender, ExecutedRoutedEventArgs e)
        {
            // MessageBox.Show("online");
            //TODO:确认弹出窗，连接设备逻辑处理
            var testername = ClientInfo.EQPInfo.TesterName;
            var probername = ClientInfo.EQPInfo.ProberName;
            var USEID = ClientInfo.EQPInfo.LotList[0].UserId;
            EAPClient eapclient = new EAPClient();
            // if (CMessageBox.Show(Consts.GetTranslation("Msg_online") + "：" + "EAP OnLine" + "?", Consts.GetTranslation("Msg_ConfirmInfo"), CMessageBoxButton.OKCancel) == CMessageBoxResult.OK)
            // {
            //调用server true online
            var _return = eapclient.StartProgram(testername, probername);
            if (_return != null && _return.ReturnCode == "0")
            {
                ClientInfo.EQPInfo.AuotoProcess = true;
                var messages = TranslateMsg.GetTranslation(CItems.AutomaticOperation);
                MainViewModel.Current.ShowMsg(MessageType.Info, messages[RunService.Current.ClientLanguage], MessageOrigin.EAP);
            }
            // }
        }
        ///// <summary>
        ///// Ctrl+F
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        private void CommandBinding_Executed_Offline(object sender, ExecutedRoutedEventArgs e)
        {

            //TODO:确认弹出窗，断开设备逻辑处理
            var testername = ClientInfo.EQPInfo.TesterName;
            var probername = ClientInfo.EQPInfo.ProberName;
            var USEID = ClientInfo.EQPInfo.LotList[0].UserId;
            EAPClient eapclient = new EAPClient();
            //   if (CMessageBox.Show(Consts.GetTranslation("Msg_online") + "：" + "EAP OffLine" + "?", Consts.GetTranslation("Msg_ConfirmInfo"), CMessageBoxButton.OKCancel) == CMessageBoxResult.OK)
            //  {
            //调用server false offline
            var _return = eapclient.SendStopProcess(testername, probername);
            if (_return != null && _return.ReturnCode == "0")
            {
                ClientInfo.EQPInfo.AuotoProcess = false;
                ClientInfo.EQPInfo.LotList = new System.Collections.ObjectModel.ObservableCollection<C_LotInfo>();
                ClientInfo.EQPInfo.LotList.Add(new C_LotInfo() { UserId = USEID });
                var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                MainViewModel.Current.ShowMsg(MessageType.Info, messages[RunService.Current.ClientLanguage], MessageOrigin.EAP);

            }
            // }

        }
        private void ButtonListen_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                C_LotInfo lot = new C_LotInfo();
                lot.LoginBox("1");

                //this.btnListen.Background = Brushes.Red;

            }
            catch (Exception ex)
            {
                CMessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 针对flex tester 出现lotend弹框,从eap方触发重新download
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonResetTester(object sender, RoutedEventArgs e)
        {
            if (CMessageBox.Show(Consts.GetTranslation("Msg_ConfirmToResetTester"), CMessageBoxButton.OKCancel) == CMessageBoxResult.OK)
            {
                //todo
            }
            else
            {

            }

        }

        /// <summary>
        /// 主service normallog实现内容上滚动 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            try
            {
                var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
                eventArg.RoutedEvent = UIElement.MouseWheelEvent;
                eventArg.Source = sender;
                // scrollbar.RaiseEvent(eventArg);
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(ex.ToString());
            }
        }
        /// <summary>
        /// 清空前端数据事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonClear_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SubBaseForm sb = new SubBaseForm("数据清除中,请稍候...");
                SubBaseForm.DelegateNonParmAndNonReturn my = new SubBaseForm.DelegateNonParmAndNonReturn(ClearLotInfo);
                sb.NonParmAndNonReturnMethod(my);


            }
            catch (Exception ex)
            {
                CMessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 手动触发lot end（出站） 按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonTrackOut_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ClientInfo.TrackOutBtn == "LotEnd")
                {
                    eapstate = "LotEnd";
                    //btnTrackOut.Content = "TrackOut";
                    ClientInfo.TrackOutBtn = "TrackOut";
                    return;
                }
                if (ClientInfo.TrackOutBtn == "TrackOut")
                {
                    ClientInfo.TrackOutBtn = "LotEnd";
                    traytransferDic.Remove(EQPStatus.currenteqpid);
                    eapstate = "TrackOut";
                    C_LotInfo lot = new C_LotInfo();
                    lot.TrackOutLogin("1");
                }
                if (ClientInfo.TrackOutBtn == "批次结束")
                {
                    eapstate = "LotEnd";
                    ClientInfo.TrackOutBtn = "出站";
                    return;
                }
                if (ClientInfo.TrackOutBtn == "出站")
                {
                    ClientInfo.TrackOutBtn = "批次结束";
                    traytransferDic.Remove(EQPStatus.currenteqpid);
                    eapstate = "TrackOut";
                    C_LotInfo lot = new C_LotInfo();
                    lot.TrackOutLogin("1");
                }
            }
            catch (Exception ex)
            {
                CMessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 退出按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                if (CMessageBox.Show("是否确定退出EAPClient?", "确认信息", CMessageBoxButton.OKCancel) == CMessageBoxResult.OK)
                {
                    //barcodeCatcher.Stop();

                    XfwContext.TerminateXfw();
                    System.Environment.Exit(0);

                }
            }
            catch (Exception ex)
            {
                System.Environment.Exit(0);
            }
        }

        /// <summary>
        /// 屏蔽客户端回车事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            //try
            //{
            //    if (e.Key == Key.Enter || e.Key == Key.Space)
            //        e.Handled = true;
            //}
            //catch (Exception ex)
            //{
            //    ServiceLogger.Error("Window_PreviewKeyDown>" + ex);
            //}
        }
        /// <summary>
        /// 关闭客户端
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Closed(object sender, EventArgs e)
        {
            if (CMessageBox.Show(Consts.GetTranslation("Msg_Exit"), Consts.GetTranslation("Msg_ConfirmInfo"), CMessageBoxButton.OKCancel) == CMessageBoxResult.OK)
            {
                System.Environment.Exit(0);
                XfwContext.TerminateXfw();
            }
        }
        private DateTime dt = DateTime.Now;  //定义一个成员函数用于保存每次的时间点       
        /// <summary>
        ///Lot文本框 按回车事件  限制手动输入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextBox_KeyDown(object sender, KeyEventArgs e)
        {

            //if (string.IsNullOrEmpty(txt_lotID.Text))
            //{
            //    dt = DateTime.Now;
            //}
            //if (e.KeyStates == Keyboard.GetKeyStates(Key.Return)|| e.KeyStates == Keyboard.GetKeyStates(Key.Tab))
            //{
            //    txt_ProberCardID.Focus();
            //}
            //else
            //{
            //    if ((dt.Ticks + 5000000) > DateTime.Now.Ticks)
            //    {
            //        txt_lotID.Text = txt_lotID.Text;
            //    }
            //    else
            //    {
            //        txt_lotID.Text = string.Empty;
            //    }
            //}
            //if (e.KeyStates == Keyboard.GetKeyStates(Key.Return) || e.KeyStates == Keyboard.GetKeyStates(Key.Tab))
            if (e.Key == Key.Return || e.Key == Key.Tab)
            {
                ServiceLogger.Debug(string.Format("{0}:", e.Key));
                
                Txt_ProberCardID.Focus();
            }
        }

        private DateTime _dt = DateTime.Now;  //定义一个成员函数用于保存每次的时间点     
        /// <summary>
        /// 探针卡输入框 限制手动输入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txt_ProberCardID_KeyDown(object sender, KeyEventArgs e)
        {
            //if (string.IsNullOrEmpty(txt_ProberCardID.Text))
            //{
            //    _dt = DateTime.Now;
            //}
            //if (e.KeyStates == Keyboard.GetKeyStates(Key.Return) || e.KeyStates == Keyboard.GetKeyStates(Key.Tab))
            //{

            //}
            //else
            //{
            //    if ((_dt.Ticks + 5000000) > DateTime.Now.Ticks)
            //    {
            //        txt_ProberCardID.Text = txt_ProberCardID.Text;
            //    }
            //    else
            //    {
            //        txt_ProberCardID.Text = string.Empty;
            //    }
            //}
        }




        //public void ProgressBarShow()
        //{
        //    ProgressBar progress = new ProgressBar();
        //    progress.WindowStartupLocation = WindowStartupLocation.CenterOwner;
        //    progress.Owner = this;
        //    progress.ShowDialog();

        //}

        //public delegate void DeleFunc();
        //public void Func()
        //{

        //    //使用ui元素   
        //   // this.btn_Clear.ToolTip = "正在清除Lot信息,请稍后...";

        //}


        public void ClearLotInfo()
        {
            try
            {
                var messages = TranslateMsg.GetTranslation("LotClearBeing");
                if (!(messages == null || messages.Count == 0))
                {
                    ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Info, messages[RunService.Current.ClientLanguage]);
                    XfwContext.DbLogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                }
                EAPClient eapclient = new EAPClient();
                //调用server false offline                         
                eapclient.SendStopProcess(ClientInfo.EQPInfo.TesterName, ClientInfo.EQPInfo.ProberName);
                var USEID = ClientInfo.EQPInfo.LotList[0].UserId;
                MainViewModel.Current.Probercardid = "";
                MainViewModel.Current.Lotid = "";
                c_LotInfo.Clear();
                #region old Code
                //ClientInfo.EQPInfo.LotList[0].LotId = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].Qty = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].State = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].ProductId = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].ProberRecipe = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].TesterProgram = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].Probercard = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].LotsStatus = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].StageId = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].Priority = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].SlotMaps = null;
                //ClientInfo.EQPInfo.LotList[0].UNITLIST = null;
                //if (ClientInfo.EQPInfo.LotList[0].UserId == null)
                //{
                //    ClientInfo.EQPInfo.BtnOk = Visibility.Collapsed;
                //    ClientInfo.EQPInfo.Btnclean = Visibility.Collapsed;
                //}
                //else
                //{
                //    ClientInfo.EQPInfo.BtnOk = Visibility.Visible;
                //    ClientInfo.EQPInfo.Btnclean = Visibility.Visible;
                //}
                #endregion

                Thread.Sleep(5000);
                // 调用server true online
                eapclient.StartProgram(ClientInfo.EQPInfo.TesterName, ClientInfo.EQPInfo.ProberName);
                Model.RunService.Current.ScanModelInfo = new ScanModel();
                //clear清空所有的magazine
                if (EQPStatus.MagazineList.Contains(EQPStatus.currenteqpid))
                    magazineDic.Remove(EQPStatus.currenteqpid);
                if (EQPStatus.TrayList.Contains(EQPStatus.currenteqpid))
                {
                    trayDic.Remove(EQPStatus.currenteqpid);
                }
                if (EQPStatus.TrayTransferList.Contains(EQPStatus.currenteqpid))
                {
                    traytransferDic.Remove(EQPStatus.currenteqpid);
                }
                messages = TranslateMsg.GetTranslation("LottClearEnd");
                if (!(messages == null || messages.Count == 0))
                {
                    ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Info, messages[RunService.Current.ClientLanguage]);
                    XfwContext.DbLogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                }
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
        }
    }
}
